<?php
namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset="UTF-8"');
class ShopcartController extends CommonController {
    public function _initialize(){
        parent::_initialize();
    }
    public function index(){
        $uid=$_SESSION['uid'];
        $db=M('shopcart');
        $data=$db->where("uid={$uid}")->select();
        foreach ($data as $key => $value) {
           $value['property']=json_decode($value['property'],true);
           $data[$key]['property']= $value['property'];
        }
        $this->assign('data',$data);

        $dc=M('shopcart');//统计购物车的数量
        $uid=$_SESSION['uid'];
        if (!empty($uid)) {
            $dataCount=$dc->where("uid={$uid}")->select();
            $count=count($dataCount);
            $this->assign('count',$count);  
        }
       
        $this->display();
    }
    public function deleteProduct(){
        $id=I('get.id');
        $db=M('shopcart');
        $ret=$db->where("id={$id}")->delete();
        if ($ret==true) {
           $this->success('删除成功',"",2);
        }

    }
}